package com.masterclient.app.modules.search.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.httpservice.RetrofitUtil2;
import com.masterclient.app.modules.search.beans.SearchNewAssociateBean;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * 作者：sean
 * 创建时间：2017/6/25 11:44
 * 功能说明：
 */

public class SearchAssociatePresenter extends SearchAssociateContract.Presenter {

    @Override
    public Disposable searchAssociate(String keyword) {
        return toSubscribe(RetrofitUtil2.getInstance().searchAssociate(keyword),
                new Consumer<CommonBaseResponse<SearchNewAssociateBean>>(){
                    @Override
                    public void accept(CommonBaseResponse<SearchNewAssociateBean> bean) throws Exception {
                        if (bean.getCode() == 0) {
                            mView.showSearchAssociate(keyword,bean.getData().getHot_keyword());
                        }else {
                            mView.loadFailed(bean.getMsg());
                        }
                    }
                },new ThrowableConsumer(){
                    @Override
                    public void accept(Throwable o) throws Exception {
                        super.accept(o);
                        mView.loadFailed("网络异常，请重试");
                    }
                });
    }
}
